package com.tf.mxj.controller;

import com.tf.mxj.R;
import com.tf.mxj.service.OssService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "OssController", description = "上传文件接口")
@RestController
@RequestMapping("/edu_oss/fileoss")
public class OssController {
    @Autowired
    private OssService ossService;

    @Operation(summary = "文件上传")
    @PostMapping("/upload")
    public R uploadFile(@RequestParam(name = "file")MultipartFile  file){
        // 获取上传的文件
        //返回上传到oss的路径
        String url = ossService.uploadFileAvatar(file);
        //返回R对象
        return R.ok().data("url", url).message("文件上传成功");
        //使用postman测试，选择post，http://localhost:8092/edu_oss/fileoss/upload，
        //选择Body，选择类型为form-data，键为file，值为上传的文件，点击Send,
        //响应结果为{"code":20000,"data":{"url":"https://qium.oss-cn-beijing.aliyuncs.com/2022/05/09/d0c5f7a5-f0c5-4f0c-a5f0-c5f0a5f0c5f0.png"},"message":"文件上传成功"}
        //复制url，打开浏览器，粘贴url，图片显示
    }
}
